<!DOCTYPE html>
<HTML lang="en">
<HEAD>
    <title> The BBX_FileSystem object </title>
    <meta charset="UTF-8">
        
    <link href="prism.css" rel="stylesheet">
<script src="microlight.js"> </script>
<script src="prism.js"> </script>
<style>
.microlight {
    font-family : monospace;
    white-space : pre;
    background-color : white;
}
    
BODY {
    width:50em;
    margin-left:5em;
    background-color:#c0c0ff;
}

P {
   width : 50em;
}

pre {
   background-color:white;
}
</style>
</HEAD>

<BODY>
    <script src="prism.js"></script>
    <A href ="https://github.com/MalcolmMcLean"> <IMG src = "Cartoon_Owl_clip_art.png" alt="Malcolm's github site"> </A>
    <A href ="index.html"> <IMG src = "babyxrc_logo.svg" alt="Baby X Resource compiler" width = "64" height = "62"> </A>
    <A href ="BabyXFS.html"> <IMG src = "BabyXLogos/baby-x-fs-logo.svg" alt="Baby X FileSystem" width = "64" height = "62"> </A>
    &nbsp;&nbsp;
    <IMG src = "BabyXLogos/babyxfs-banner.svg" width = "256" height = "62" alt = "Baby X FS banner">
<H1>The BBX_FileSystem object </H1>
<P>
The Baby X FileSystem object, BBX_FileSystem, is a Baby X object designed to work with FileSystem XML files. The object makes it easy for programmers to use these files aand to manipulate the. It is part of the <A href = "BabyXFS.html">BabyXFS</A> or Baby X FileSystem project, whch is a project designed to allow Baby X user to mount directories. The C code is documented <A href = "bbx_filesystem.html">here</A>
</P>
<H3> A baby virtual filesystem</H3>
<P>
The BBX_FileSystem object is designed to answer the question of how to mount virtual file systems in Baby X or other small "baby" hobby programs. So like all of Baby X, the emphasis is on simplicity and portability, to give the hobby programmer an easy or "baby" component to work with. So the BBX_FileSystem object use <A href = "FileSystemXML.html">FileSystem XML</A> files, a vey clean XML format designed for Baby X, but free for anyone to use. It loads a FileSystem XML file and treates it as an internal drive which the program can query.
</P>
<P>
The object has two dependencies, a BabyXFS utilities file, and an XML parser. So three .c  files and three .h files are all you need to take to use it. The files are hosted on github, <A href ="https://github.com/MalcolmMcLean/babyxrc">here</A>. And then you simply drop those files into your program and you can use it. It's all clean ANSI C.
</P>
<P>
And you can easily convert a folder on your machine to a FileSystem XML file using the utilities in the <A href = BabyXFS.html>BabyXFS</A> subsystem. So the object is extremely powerful and easy to use, and of course like all of Baby X, it is free for anyone to use for any purpose, thought it is mainly aimed at the hobby programmer writing small programs.
</P>
<H3>Mounting host directories</H3>
<P>
Whilst the BBX_FileSystem object is designed to be used with FileSystem XML files, you can also mount a host directory. There is of course little point doing this in a user program, as you would just use stdio and the facilities of the host operating system directly, But it is a development tool. Whilst developing the program you set the BBX_FileSystem object to BBX_FS_ANSI mode, and it use the host directory. Any you've all the facilities of the host machine for editing that folder. Then when the program is near release, and you have settled on the resource files, you convert to a FileSystem XML file using the BabyXFS tool babyxfs_dirtoxml, and switch the object to BBX_FS_STRING mode.
</P>
<H3>The functions </H3>

<P>

These are the functions in the library.

</P>
<pre><code class="language-c">
    //
    //  bbx_filesystem.h
    //  babyxfs
    //
    //  Created by Malcolm McLean on 31/05/2024.
    //

    #ifndef bbx_filesystem_h
    #define bbx_filesystem_h

    #define BBX_FS_STDIO 1
    #define BBX_FS_STRING 2

    typedef struct bbx_filesystem BBX_FileSystem;

    BBX_FileSystem *bbx_filesystem(void);
    void bbx_filesystem_kill(BBX_FileSystem *bbx_fs);
    int bbx_filesystem_set(BBX_FileSystem *bbx_fs, const char *pathorxml, int mode);
    FILE *bbx_filesystem_fopen(BBX_FileSystem *bbx_fs, const char *path, const char *mode);
    int bbx_filesystem_fclose(BBX_FileSystem *bbx_fs, FILE *fp);
    char *bbx_filesystem_slurp(BBX_FileSystem *bbx_fs, const char *path, const char *mode);
    unsigned char *bbx_filesystem_slurpb(BBX_FileSystem *bbx_fs, const char *path, const char *mode, int *N);
    int bbx_filesystem_unlink(BBX_FileSystem *bbx_fs, const char *path);
    const char *bbx_filesystem_getname(BBX_FileSystem *bbx_fs);
    int bbx_filesystem_setreadir(BBX_FileSystem *bbx_fs, char **(*fptr)(const char *path, void *ptr), void *ptr);
    int bbx_filesystem_dump(BBX_FileSystem *bbx_fs, FILE *fp);
    char **bbx_filesystem_mkdir(BBX_FileSystem *bbx_fs, const char *path);
    char **bbx_filesystem_rmdir(BBX_FileSystem *bbx_fs, const char *path);
    char **bbx_filesystem_list(BBX_FileSystem *bbx_fs, const char *path);

    #endif /* bbx_filesystem_h */
</code></pre>

</BODY> </HTML>

